//
//  NewSliderView.m
//  LSYReader
//
//  Created by 王欣 on 2017/12/23.
//  Copyright © 2017年 okwei. All rights reserved.
//

#import "CBCSliderView.h"
#import "CommonFuctions.h"
#if __has_include(<Masonry/Masonry.h>)
#import <Masonry/Masonry.h>
#else
#import "Masonry.h"
#endif
@interface CBCSliderView()

@end
CGFloat   sliderHeight = 30;
#define   sliderColor [UIColor orangeColor]
@implementation CBCSliderView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }return self;
}

-(void)setupUI{


    [self addSubview:self.slider];
    [self addSubview:self.nextBtn];
    [self addSubview:self.preBtn];

    [self.preBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.centerY.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(45, 45));
    }];
    [self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-10);
        make.centerY.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(45, 45));
    }];
    [self.slider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(_preBtn.mas_right).offset(5);
        make.height.equalTo(self);
        make.right.equalTo(_nextBtn.mas_left).offset(-5);
    }];
}

-(TTRangeSlider *)slider{
    if (!_slider) {
        _slider = [[TTRangeSlider alloc]init];
        _slider.disableRange = YES;
        _slider.minValue = 0.0;
        _slider.maxValue = 100.0;
        _slider.tintColor = [UIColor whiteColor];
        _slider.selectedMaximum = 0;
        NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
        formatter.positiveSuffix = @"%";
        _slider.numberFormatterOverride = formatter;
        _slider.selectedMinimum = 0;
        _slider.tintColorBetweenHandles = sliderColor;
        _slider.handleColor = sliderColor;
        _slider.maxLabelColour = sliderColor;
        _slider.enableStep = YES;
    }return _slider;
}
-(UIButton *)nextBtn{
    if (!_nextBtn) {
        _nextBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        
        [_nextBtn setImage:[CommonFuctions cbcReaderImage:@"nextChapter"] forState:(UIControlStateNormal)];
        [_nextBtn setImage:[CommonFuctions cbcReaderImage:@"nextChapterSel"] forState:(UIControlStateDisabled)];
        
    }return _nextBtn;
}
-(UIButton *)preBtn{
    if (!_preBtn) {
        _preBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_preBtn setImage:[CommonFuctions cbcReaderImage:@"preChapter"] forState:(UIControlStateNormal)];
        [_preBtn setImage:[CommonFuctions cbcReaderImage:@"preChapterSel"] forState:(UIControlStateDisabled)];

    }return _preBtn;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
